package com.villaday.idf.fragment;


import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcelable;
import androidx.annotation.IdRes;
import androidx.annotation.RequiresApi;
import androidx.viewpager.widget.ViewPager;
import androidx.core.widget.NestedScrollView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewTreeObserver;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.squareup.picasso.Picasso;
import com.squareup.picasso.Target;
import com.tencent.mm.opensdk.modelmsg.SendMessageToWX;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import com.tencent.mm.opensdk.modelmsg.WXMiniProgramObject;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;
import com.villaday.idf.R;
import com.villaday.idf.activity.BackHandlerHelper;
import com.villaday.idf.activity.ChouseCheckInDateActivity;
import com.villaday.idf.activity.FacilitiesActivity;
import com.villaday.idf.activity.FragmentBackHandler;
import com.villaday.idf.activity.HouseDetailsActivityFor3;
import com.villaday.idf.adapter.DateCalendarAdapter;
import com.villaday.idf.adapter.HomeFacilityAdapterOutSide;
import com.villaday.idf.adapter.SimilarListAdapter;
import com.villaday.idf.base.AbsRecyclerViewAdapter;
import com.villaday.idf.base.BaseFragment;
import com.villaday.idf.custom.LoadingDialog;
import com.villaday.idf.custom.mzbanner.MZBannerView;
import com.villaday.idf.custom.mzbanner.holder.MZHolderCreator;
import com.villaday.idf.custom.mzbanner.holder.MZViewHolder;
import com.villaday.idf.custom.pop.SharePop;
import com.villaday.idf.custom.pop.ZXPopPT;
import com.villaday.idf.imp.ChangeFaImp;
import com.villaday.idf.imp.GoodsDeticalChangeTitleImp;
import com.villaday.idf.model.Favor;
import com.villaday.idf.model.HousesStates;
import com.villaday.idf.model.MYHousesEntity;
import com.villaday.idf.model.RefreshtokenEntity;
import com.villaday.idf.model.SheBeiEntity;
import com.villaday.idf.model.SimilarListEntity;
import com.villaday.idf.model.behaviorsEntity;
import com.villaday.idf.model3.AllPostersEntity;
import com.villaday.idf.model3.customerServiceStaffEntity;
import com.villaday.idf.util.BitMapUtil;
import com.villaday.idf.util.Constant;
import com.villaday.idf.util.LogeUtil;
import com.villaday.idf.util.OkHttpUtil;
import com.villaday.idf.util.PhoneUtil;
import com.villaday.idf.util.ShareUtils;
import com.villaday.idf.util.SharedPreferencesUtil;
import com.villaday.idf.util.ToastUtil;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.OnClick;
import byc.imagewatcher.ImageWatcher;
import io.reactivex.functions.Consumer;
import me.bakumon.statuslayoutmanager.library.OnStatusChildClickListener;
import me.bakumon.statuslayoutmanager.library.StatusLayoutManager;

/**
 * 商品3期
 */
public class GoodsHouseFragmentFor3 extends BaseFragment implements MZBannerView.BannerPageClickListener, RadioGroup.OnCheckedChangeListener, OkHttpUtil.OnDataListener, AbsRecyclerViewAdapter.OnItemClickListener, FragmentBackHandler {

    @BindView(R.id.banner)
    MZBannerView mMZBanner;
    /*@BindView(R.id.cv_countdownViewTest4)
    CountdownView cvCountdownViewTest4;*/
    @BindView(R.id.rg)
    RadioGroup rg;
    @BindView(R.id.view_0)
    View view0;
    @BindView(R.id.view_1)
    View view1;
    @BindView(R.id.view_2)
    View view2;
    @BindView(R.id.view_00)
    View view00;
    @BindView(R.id.view_11)
    View view11;
    @BindView(R.id.view_22)
    View view22;
    @BindView(R.id.tv_h5)
    WebView tvH5;
    @BindView(R.id.tv_page)
    TextView tvPage;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_zhu)
    TextView tvZhu;

    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_addr)
    TextView tvAddr;
    @BindView(R.id.rb_0)
    RadioButton rb0;
    @BindView(R.id.rb_1)
    RadioButton rb1;
    @BindView(R.id.rb_2)
    RadioButton rb2;
    @BindView(R.id.ll)
    LinearLayout ll;


    @BindView(R.id.tv_yun)
    TextView tvYun;
    @BindView(R.id.tv_yuanNum)
    TextView tvYuanNum;
    @BindView(R.id.tv_PerCapita)
    TextView tvPerCapita;
    @BindView(R.id.rv_facilities)
    RecyclerView rvFacilities;
    @BindView(R.id.tv_zx)
    TextView tvZx;
    @BindView(R.id.tv_openAndClose)
    TextView tvOpenAndClose;
    @BindView(R.id.viewalph)
    View viewAlph;
    @BindView(R.id.rv_sameHouse)
    RecyclerView tvSameHouse;
    @BindView(R.id.rv_date)
    RecyclerView rvDate;
    @BindView(R.id.toolbar_iconLeft)
    ImageButton toolbarIconLeft;
    @BindView(R.id.tv_date)
    TextView tvDate;
    @BindView(R.id.toolbar_iconRight)
    ImageButton toolbarIconRight;
    @BindView(R.id.ll_openAndClose)
    LinearLayout llOpenAndClose;
    @BindView(R.id.tv_change)
    TextView tvChange;
    @BindView(R.id.tv_tg)
    TextView tv_tg;
    @BindView(R.id.tv_buy)
    TextView tv_buy;
    @BindView(R.id.tv_buy1)
    TextView tv_buy1;
    @BindView(R.id.tv_favorite)
    TextView tvFavorite;

    @BindView(R.id.tv_xiajia)
    TextView tvXiajia;

   /* @BindView(R.id.rl_zhuan)
    RelativeLayout rlZhuan;*/

    @BindView(R.id.tv_zhuanNum)
    TextView tvZhuanNum;
    /*@BindView(R.id.tv_qi)
    TextView tvQI;*/

    @BindView(R.id.ll_head)
    NestedScrollView ll_head;

    @BindView(R.id.view_0_1)
    View view_0_1;

    @BindView(R.id.view_1_2)
    View view_1_2;

    @BindView(R.id.tv_shi)
    TextView tv_shi;
    @BindView(R.id.tv_ren)
    TextView tv_ren;
    @BindView(R.id.tv_mi)
    TextView tv_mi;

    @BindView(R.id.tv_renren)
    TextView tv_renren;

    @BindView(R.id.fab)
    FloatingActionButton fab;

    @BindView(R.id.tv_manjian)
    TextView tv_manjian;

    @BindView(R.id.ll_rotype)
    LinearLayout ll_rotype;



    @BindView(R.id.fl_history)
    TagFlowLayout fl_history;

    @BindView(R.id.viwe_kefu)
    View viwe_kefu;

    @BindView(R.id.ll_xiangsi)
    LinearLayout ll_xiangsi;


    private int pageNo = 1;


    private Html.ImageGetter imgGetter;
    private String houseId;
    private LoadingDialog loadingDialog;
    private Gson gson = new GsonBuilder().create();
    private ChangePage changePage;
    private MYHousesEntity mYHousesEntity;
    List<SimilarListEntity.BodyEntity.DataListEntity> sameData = new ArrayList<>();
    List<HousesStates.BodyEntity.MonthsEntity> dateCalendar = new ArrayList<>();

    private SimilarListAdapter similarListAdapter;
    private Map<String, String> datemap = new HashMap<>();
    private String currentTime = "";
    private DateCalendarAdapter dateCalendarAdapter;
    private int sizeCalendar = -1;//日历集合大小
    private int currentCalendar;
    private HousesStates housesStates;
    private StatusLayoutManager statusLayoutManager;
    private int showNum;
    private GoodsDeticalChangeTitleImp goodsDeticalChangeTitleImp;
    private ChangeFaImp onChangeFa;
    private GoodsFragmentFor3.ChangeTabPosition changeTabPosition;

    private ImageWatcher vImageWatcher;
    private AllPostersEntity.BodyBean allPostersEntity;
    public GoodsHouseFragmentFor3() {
        // Required empty public constructor
    }

    public void setChangeFaImp(ChangeFaImp onChangeFa) {

        this.onChangeFa = onChangeFa;
    }

    public static GoodsHouseFragmentFor3 instance(String persellId) {
        GoodsHouseFragmentFor3 homeFragment = new GoodsHouseFragmentFor3();
        Bundle bundle = new Bundle();
        bundle.putString("houseId", persellId);
        homeFragment.setArguments(bundle);
        return homeFragment;
    }

    @Override
    protected int getViewResId() {
        return R.layout.fragment_goods_housefor3;
    }

    public void setGoodsDeticalChangeTitleImp(GoodsDeticalChangeTitleImp goodsDeticalChangeTitleImp) {

        this.goodsDeticalChangeTitleImp = goodsDeticalChangeTitleImp;
    }
    private void initSharePop() {
        mRxManager.on("sharepopEntity", new Consumer<AllPostersEntity.BodyBean>() {

            @Override
            public void accept(AllPostersEntity.BodyBean bodyBean) throws Exception {

                allPostersEntity = bodyBean;
            }
        });
        mRxManager.on("sharepop", new Consumer<ImageWatcher>() {
            @Override
            public void accept(ImageWatcher imageWatcher) throws Exception {
                vImageWatcher = imageWatcher;
                vImageWatcher.setImageWatcherOndismiss(new ImageWatcher.ImageWatcherDiss() {
                    @Override
                    public void onImageWatcherDiss() {
                        if (allPostersEntity!=null){
                            SharePop sharePop = new SharePop(GoodsHouseFragmentFor3.this,getActivity(), getActivity(), allPostersEntity);
                            sharePop.showPopupWindow();
                        }
                    }
                });
            }
        });
    }

    @Override
    protected void init(View v) {
        if (SharedPreferencesUtil.getAgreementTuiJian(getContext())) {

            ll_xiangsi.setVisibility(View.VISIBLE);
            tvSameHouse.setVisibility(View.VISIBLE);
        } else {
            ll_xiangsi.setVisibility(View.GONE);
            tvSameHouse.setVisibility(View.GONE);

        }

        ll_head.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() {
            @Override
            public void onScrollChange(NestedScrollView nestedScrollView, int i, int i1, int i2, int i3) {
                if (PhoneUtil.isVisible(getActivity(), ll_xiangsi)) {
                    changeTabPosition.changeTabPosition(1, ll_xiangsi);
                } else {
                    changeTabPosition.changeTabPosition(0, ll_xiangsi);

                }
            }
        });

        Map<String, String> map = new HashMap<>();
        map.put("action", "assign");
        OkHttpUtil.getJSON(getContext(), Constant.URL.customerServiceStaff, map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                if (!TextUtils.isEmpty(json)) {
                    customerServiceStaffEntity customerServiceStaffEntity = gson.fromJson(json, customerServiceStaffEntity.class);
                    if ("200".equals(customerServiceStaffEntity.getCode())) {
                        com.villaday.idf.model3.customerServiceStaffEntity.BodyBean bodyzc = customerServiceStaffEntity.getBody();
                        // Glide.with(context).asBitmap().load(body.getProfilePicture()).into(img_head);

                        if (bodyzc.isOnline()) {
                            viwe_kefu.setSelected(true);
                        } else {
                            viwe_kefu.setSelected(false);

                        }

                    } else {

                    }
                }
            }

            @Override
            public void onFailure(String url, String error) {

            }
        });

        // 监听滑动的
        ViewTreeObserver viewTreeObserver = mMZBanner.getViewTreeObserver();
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @TargetApi(Build.VERSION_CODES.M)
            @Override
            public void onGlobalLayout() {
                // 这个nsv就是NestedScrollView
                ll_head.setOnScrollChangeListener(new View.OnScrollChangeListener() {
                    @SuppressLint("RestrictedApi")
                    @Override
                    public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                        // 拿到一个height
                        int height = mMZBanner.getHeight() - PhoneUtil.dp2px(getContext(), 44);
                        int mScrollY = scrollY;
                        if (goodsDeticalChangeTitleImp != null) {
                            goodsDeticalChangeTitleImp.changeTitle(scrollY, height);

                        }

                        if (scrollY <= 0) {
                            //设置标题的背景颜色
                            fab.setVisibility(View.GONE);


                        } else if (scrollY > 1 && scrollY <= height) {
                            // 滑动距离小于图的高度时，设置背景和字体颜色颜色透明度渐变
                            fab.setVisibility(View.GONE);


                        } else {
                            // 滑动到图下面设置普通颜色

                            fab.setVisibility(View.VISIBLE);
                        }
                    }
                });
            }
        });


        mMZBanner.getLayoutParams().height = (int) (PhoneUtil.getPhoneWidth(getContext()) / 1.6);
        mMZBanner.requestLayout();
        RefreshtokenEntity.BodyBean roleInfo =
                SharedPreferencesUtil.getRoleInfo(getContext());
        String roleType = roleInfo.getMember().getType();
        if ("0".equals(roleType)) {
            ll.setVisibility(View.GONE);
            tv_tg.setVisibility(View.GONE);
            tv_buy.setVisibility(View.GONE);
            tv_buy1.setVisibility(View.VISIBLE);
            //   rlZhuan.setVisibility(View.GONE);
            tv_manjian.setVisibility(View.GONE);
                ll_rotype.setVisibility(View.GONE);

        }
        //添加删除线
        long time4 = (long) 150 * 24 * 60 * 60 * 1000;
        // cvCountdownViewTest4.start(time4);

        rg.setOnCheckedChangeListener(this);
        //这里面的resource就是fromhtml函数的第一个参数里面的含有的url
        // 获取网路图片
        imgGetter = new Html.ImageGetter() {
            public Drawable getDrawable(String source) {
                Log.i("RG", "source---?>>>" + source);
                Drawable drawable = null;
                URL url;
                try {
                    url = new URL(source);
                    Log.i("RG", "url---?>>>" + url);
                    drawable = Drawable.createFromStream(url.openStream(), ""); // 获取网路图片
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }
                drawable.setBounds(0, 0, drawable.getIntrinsicWidth(),
                        drawable.getIntrinsicHeight());
                Log.i("RG", "url---?>>>" + url);
                return drawable;
            }
        };
        tvH5.getSettings().setJavaScriptEnabled(true);
        tvH5.setWebChromeClient(new WebChromeClient());
        tvH5.getSettings().setLoadsImagesAutomatically(true);
        setWebViewHight(true);
        tvOpenAndClose.setSelected(true);
        similarListAdapter = new SimilarListAdapter(getContext());

        similarListAdapter.setFullScreen(true);
        tvSameHouse.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));
        tvSameHouse.setAdapter(similarListAdapter);
        similarListAdapter.setOnItemClickListener(new AbsRecyclerViewAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View v, int position) {
                Intent intent = new Intent(getContext(), HouseDetailsActivityFor3.class);
                intent.putExtra("houseId", sameData.get(position).getId());
                intent.putExtra("brokerAge", sameData.get(position).getBrokerAge());

                startActivity(intent);
                getActivity().onBackPressed();
            }
        });


        rvDate.setLayoutManager(new LinearLayoutManager(getContext(), RecyclerView.HORIZONTAL, false));
        dateCalendarAdapter = new DateCalendarAdapter(getContext());
        rvDate.setAdapter(dateCalendarAdapter);
        rvDate.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return true;
            }
        });

        statusLayoutManager = setupDefaultStatusLayoutManager(ll_head, new OnStatusChildClickListener() {
            @Override
            public void onEmptyChildClick(View view) {

            }

            @Override
            public void onErrorChildClick(View view) {
                loadingDialog = LoadingDialog.newInstance("加载中");
                loadingDialog.show(getActivity().getFragmentManager(), "loading");

                loadData();
            }

            @Override
            public void onCustomerChildClick(View view) {

            }
        });
        initSharePop();
    }

    public void setGoToTuiJian() {
        ll_head.smoothScrollTo(0, ll_xiangsi.getTop());
    }

    public void setGoToTop() {
        if (ll_head != null) {
            ll_head.smoothScrollTo(0, 0);

        }
    }

    private void setWebViewHight(boolean isMatch) {
        if (isMatch) {
            tvH5.getLayoutParams().height = RelativeLayout.MarginLayoutParams.WRAP_CONTENT;
        } else {
            tvH5.getLayoutParams().height = PhoneUtil.dp2px(getContext(), 250);

        }
        tvH5.requestLayout();
    }

    public void setChangePage(ChangePage changePage) {

        this.changePage = changePage;
    }


    @Override
    protected void loadData() {

        loadingDialog = LoadingDialog.newInstance("加载中");
        loadingDialog.show(getActivity().getFragmentManager(), "loading");
        houseId = getArguments().getString("houseId");
        OkHttpUtil.getJSON(getContext(), Constant.URL.houses + houseId, this);

        getSameHouse();

        getCalendar();

    }

    private void getCalendar() {
        houseId = getArguments().getString("houseId");
        datemap.clear();
        datemap.put("month", currentTime);
        datemap.put("size", 6 + "");
        OkHttpUtil.getJSON(getContext(), String.format(Constant.URL.houses_states, houseId), datemap, this);
    }

    private void getSameHouse() {
        houseId = getArguments().getString("houseId");
        Map<String, String> map = new HashMap<>();
        map.put("pageNo", pageNo + "");
        OkHttpUtil.getJSON(getContext(), String.format(Constant.URL.similar_list, houseId), map, this);


    }


    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    private void initview(final MYHousesEntity mYHousesEntity) {

        fab.setBackgroundTintMode(PorterDuff.Mode.SRC_OVER);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ll_head.scrollTo(0, 0);

            }
        });


        tvFavorite.setSelected(mYHousesEntity.getBody().isFavorite());
        if (onChangeFa != null) {
            onChangeFa.onChangeFa(tvFavorite.isSelected());
        }
        tvZhuanNum.setText(mYHousesEntity.getBody().getBrokerAgeAmountValue());
        //tvQI.setVisibility(View.VISIBLE);
        initBanner(mYHousesEntity.getBody().getImageURLs());

        view0.setVisibility(View.VISIBLE);
        if (mYHousesEntity.getBody().getDetail() != null) {
            // tvH5.loadDataWithBaseURL("图书名", mYHousesEntity.getBody().getHouse().getDetail(), "text/html", "utf-8", null);

            if (mYHousesEntity.getBody().getDetail() != null) {
                imageFillWidth(tvH5, mYHousesEntity.getBody().getDetail().replace("<p><br></p><p><br></p>", ""));

            }
            if (TextUtils.isEmpty(mYHousesEntity.getBody().getDetail())) {//无详情
                rb0.setVisibility(View.GONE);
                view0.setVisibility(View.GONE);
                view00.setVisibility(View.GONE);
                showNum = showNum + 1;
            }
            if (TextUtils.isEmpty(mYHousesEntity.getBody().getVillage().getAround())) {//周边玩乐
                rb1.setVisibility(View.GONE);
                view1.setVisibility(View.GONE);
                view00.setVisibility(View.GONE);

                showNum = showNum + 1;
            }
            if (TextUtils.isEmpty(mYHousesEntity.getBody().getVillage().getDetail())) {//小区环境
                rb2.setVisibility(View.GONE);
                view2.setVisibility(View.GONE);
                view11.setVisibility(View.GONE);
                showNum = showNum + 1;


            }
            if (showNum == 1) {
                view_0_1.setVisibility(View.GONE);

            }
            if (showNum == 2) {
                view_1_2.setVisibility(View.GONE);
                view_0_1.setVisibility(View.GONE);

            }


            tvName.setText(mYHousesEntity.getBody().getName());
            tvZhu.setText("房屋编号：" + mYHousesEntity.getBody().getNumber());
            tvAddr.setText(mYHousesEntity.getBody().getLocation().getAddress());
            tvYun.setText(Html.fromHtml("&yen;"));
            PhoneUtil.setExternalFont(getContext(), tvYuanNum, true);

            tvYuanNum.setText(mYHousesEntity.getBody().getCurrentPriceValue());
//            tvPerCapita.setText(Html.fromHtml("人均&yen;" + mYHousesEntity.getBody().getAveragePriceValue()));
            tvPerCapita.setText(Html.fromHtml("人均&yen;" + mYHousesEntity.getBody().getAveragePriceValue() + "起"));
            //tvH5.setText(Html.fromHtml(mYHousesEntity.getBody().getHouse().getDetail(), new URLImageGetter(tvH5, getContext()), null));
            rvFacilities.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));

            HomeFacilityAdapterOutSide homeFacilityAdapter = new HomeFacilityAdapterOutSide(getContext());
            homeFacilityAdapter.setFullScreen(true);//设置横向不全屏

            rvFacilities.setAdapter(homeFacilityAdapter);
            List<SheBeiEntity> ssData = new ArrayList<>();
            List<MYHousesEntity.BodyEntity.FacilitiesEntity> base = mYHousesEntity.getBody().getFacilities();
            for (int i = 0; i < base.size(); i++) {
                ssData.add(new SheBeiEntity(base.get(i).getCode(), base.get(i).getIcon(), base.get(i).getIconClass(), base.get(i).getName()));
            }

            tv_renren.setText((mYHousesEntity.getBody().getHouseType() == 3 ? "可玩" : "宜住"));
            tv_shi.setText(mYHousesEntity.getBody().getRoomNum() + "室" + mYHousesEntity.getBody().getHallNum() + "厅" + mYHousesEntity.getBody().getBedNum() + "床");
            tv_ren.setText(mYHousesEntity.getBody().getPeopleNum() + "人");
            tv_mi.setText(mYHousesEntity.getBody().getAcreage() + "㎡");

            if ("0".equals(mYHousesEntity.getBody().getAddBrokerageAmountValue())){
                tvZhuanNum.setVisibility(View.GONE);
            }

            if ("0".equals(mYHousesEntity.getBody().getBrokerAgeAmountValue())){
                tv_manjian.setVisibility(View.GONE);
            }
            tvZhuanNum.setText(Html.fromHtml("加返" + "&yen;" + mYHousesEntity.getBody().getAddBrokerageAmountValue()));
            tv_manjian.setText(Html.fromHtml("立返" + "&yen;" + mYHousesEntity.getBody().getBrokerAgeAmountValue()));


            if ((mYHousesEntity.getBody().getTags() != null && mYHousesEntity.getBody().getTags().size() != 0)) {
                TagAdapter<String> tagAdapter = new TagAdapter<String>((List<String>) mYHousesEntity.getBody().getTags()) {
                    @Override
                    public View getView(FlowLayout parent, int position, String s) {

                        LayoutInflater inflater = LayoutInflater.from(getContext());
                        TextView tv;
                        tv = (TextView) inflater.inflate(R.layout.tv_home_tag, null);
                        if (s instanceof String) {
                            //当地热门

                            String hot = (String) s;
                            if (hot.length() > 10) {
                                tv.setText(hot.substring(0, 6) + "...");

                            } else {
                                tv.setText(hot);

                            }

                        }


                        return tv;
                    }
                };
                fl_history.setAdapter(tagAdapter);
            }

            homeFacilityAdapter.setData(ssData);
            homeFacilityAdapter.setOnItemClickListener(new AbsRecyclerViewAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View v, int position) {
                    if (mYHousesEntity.getBody() != null && mYHousesEntity.getBody().getFacilityMap() != null) {
                        List<SheBeiEntity> ssData = new ArrayList<>();
                        MYHousesEntity.BodyEntity.FacilityMapEntity facilityMap = mYHousesEntity.getBody().getFacilityMap();
                        if (facilityMap.getFEATURE() != null && facilityMap.getFEATURE().size() > 0) {
                            for (int i = 0; i < facilityMap.getFEATURE().size(); i++) {
                                ssData.add(new SheBeiEntity(facilityMap.getFEATURE().get(i).getCode(), facilityMap.getFEATURE().get(i).getIcon(), facilityMap.getFEATURE().get(i).getIconClass(), facilityMap.getFEATURE().get(i).getName()));

                            }
                            for (int i = 0; i < 4 - facilityMap.getFEATURE().size() % 4; i++) {
                                ssData.add(new SheBeiEntity(1));
                            }
                        }

                        if (facilityMap.getBASE() != null && facilityMap.getBASE().size() > 0) {
                            for (int i = 0; i < facilityMap.getBASE().size(); i++) {
                                ssData.add(new SheBeiEntity(facilityMap.getBASE().get(i).getCode(), facilityMap.getBASE().get(i).getIcon(), facilityMap.getBASE().get(i).getIconClass(), facilityMap.getBASE().get(i).getName()));

                            }
                            for (int i = 0; i < 4 - facilityMap.getBASE().size() % 4; i++) {
                                ssData.add(new SheBeiEntity(1));
                            }
                        }

                        if (facilityMap.getRECREATION() != null && facilityMap.getRECREATION().size() > 0) {
                            for (int i = 0; i < facilityMap.getRECREATION().size(); i++) {
                                ssData.add(new SheBeiEntity(facilityMap.getRECREATION().get(i).getCode(), facilityMap.getRECREATION().get(i).getIcon(), facilityMap.getRECREATION().get(i).getIconClass(), facilityMap.getRECREATION().get(i).getName()));

                            }
                            for (int i = 0; i < 4 - facilityMap.getRECREATION().size() % 4; i++) {
                                ssData.add(new SheBeiEntity(1));
                            }
                        }
                        if (facilityMap.getCLEAN_TOOL() != null && facilityMap.getCLEAN_TOOL().size() > 0) {
                            for (int i = 0; i < facilityMap.getCLEAN_TOOL().size(); i++) {
                                ssData.add(new SheBeiEntity(facilityMap.getCLEAN_TOOL().get(i).getCode(), facilityMap.getCLEAN_TOOL().get(i).getIcon(), facilityMap.getCLEAN_TOOL().get(i).getIconClass(), facilityMap.getCLEAN_TOOL().get(i).getName()));

                            }
                            for (int i = 0; i < 4 - facilityMap.getCLEAN_TOOL().size() % 4; i++) {
                                ssData.add(new SheBeiEntity(1));
                            }
                        }
                        if (facilityMap.getCLEAN_FACILITY() != null && facilityMap.getCLEAN_FACILITY().size() > 0) {
                            for (int i = 0; i < facilityMap.getCLEAN_FACILITY().size(); i++) {
                                ssData.add(new SheBeiEntity(facilityMap.getCLEAN_FACILITY().get(i).getCode(), facilityMap.getCLEAN_FACILITY().get(i).getIcon(), facilityMap.getCLEAN_FACILITY().get(i).getIconClass(), facilityMap.getCLEAN_FACILITY().get(i).getName()));

                            }
                            for (int i = 0; i < 4 - facilityMap.getCLEAN_FACILITY().size() % 4; i++) {
                                ssData.add(new SheBeiEntity(1));
                            }
                        }
                        if (facilityMap.getREPAST() != null && facilityMap.getREPAST().size() > 0) {
                            for (int i = 0; i < facilityMap.getREPAST().size(); i++) {
                                ssData.add(new SheBeiEntity(facilityMap.getREPAST().get(i).getCode(), facilityMap.getREPAST().get(i).getIcon(), facilityMap.getREPAST().get(i).getIconClass(), facilityMap.getREPAST().get(i).getName()));

                            }
                            for (int i = 0; i < 4 - facilityMap.getREPAST().size() % 4; i++) {
                                ssData.add(new SheBeiEntity(1));
                            }
                        }
                        if (facilityMap.getAROUND() != null && facilityMap.getAROUND().size() > 0) {
                            for (int i = 0; i < facilityMap.getAROUND().size(); i++) {
                                ssData.add(new SheBeiEntity(facilityMap.getAROUND().get(i).getCode(), facilityMap.getAROUND().get(i).getIcon(), facilityMap.getAROUND().get(i).getIconClass(), facilityMap.getAROUND().get(i).getName()));

                            }
                            for (int i = 0; i < 4 - facilityMap.getAROUND().size() % 4; i++) {
                                ssData.add(new SheBeiEntity(1));
                            }
                        }
                        if (facilityMap.getOTHER() != null && facilityMap.getOTHER().size() > 0) {
                            for (int i = 0; i < facilityMap.getOTHER().size(); i++) {
                                ssData.add(new SheBeiEntity(facilityMap.getOTHER().get(i).getCode(), facilityMap.getOTHER().get(i).getIcon(), facilityMap.getOTHER().get(i).getIconClass(), facilityMap.getOTHER().get(i).getName()));

                            }
                            for (int i = 0; i < 4 - facilityMap.getOTHER().size() % 4; i++) {
                                ssData.add(new SheBeiEntity(1));
                            }
                        }


                        Intent intent2 = new Intent(getContext(), FacilitiesActivity.class);
                        intent2.putParcelableArrayListExtra("data", (ArrayList<? extends Parcelable>) ssData);
                        startActivity(intent2);
                    }

                }
            });
        }


    }

    /**
     * 处理图片视频填充手机宽度
     *
     * @param webView <p><br/></p>
     */
    @RequiresApi(api = Build.VERSION_CODES.KITKAT)
    private void imageFillWidth(WebView webView, String htmlStr) {
        //htmlStr.replace("height: 100%","height: auto");
        Document doc = Jsoup.parse(htmlStr);

        //修改视频标签
        Elements embeds = doc.getElementsByTag("embed");
        for (Element element : embeds) {
            //宽度填充手机，高度自适应
            element.attr("width", "100%").attr("height", "auto");
        }
        //webview 无法正确识别 embed 为视频，所以这里把这个标签改成 video 手机就可以识别了
        doc.select("embed").tagName("video");

        //控制图片的大小
        Elements imgs = doc.getElementsByTag("img");
        for (int i = 0; i < imgs.size(); i++) {
            //宽度填充手机，高度自适应
            String width = imgs.get(i).attr("width");
            if (!TextUtils.isEmpty(width)) {
                int phoneWidth = PhoneUtil.getPhoneWidth(getContext());
                try {
                    if (Integer.parseInt(width) > PhoneUtil.PixelsToDip(getContext(), phoneWidth)) {
                        imgs.get(i).attr("width", "100%").attr("height", "auto");
                    }
                } catch (Exception e) {
                    continue;
                }


            } else {
                imgs.get(i).attr("style", "width:  100%; height: auto;");

            }
        }
        //控制图片的大小
        Elements video = doc.getElementsByTag("video");
        for (int i = 0; i < video.size(); i++) {
            //宽度填充手机，高度自适应
            video.get(i).attr("style", "width: 100%; height: auto;");
        }

     /*   //控制图片的大小
        Elements section = doc.getElementsByTag("section");
        for (int i = 0; i < section.size(); i++) {
            //宽度填充手机，高度自适应
            section.get(i).attr("style", "width: 100%; height: auto;");
        }*/

        //加载使用 jsoup 处理过的 html 文本
        webView.setWebContentsDebuggingEnabled(true);

        webView.loadDataWithBaseURL(null, doc.toString(), "text/html", "UTF-8", null);
    }

    private void initBanner(final List<String> imageURLs) {
        //添加Page点击事件
        mMZBanner.setBannerPageClickListener(this);
        //设置是否显示Indicator
        mMZBanner.setIndicatorVisible(false);

        // 设置数据
        tvPage.setText("1/" + imageURLs.size());
        mMZBanner.setPages(imageURLs, new MZHolderCreator<BannerViewHolder>() {
            @Override
            public BannerViewHolder createViewHolder() {
                return new BannerViewHolder();
            }
        });
        mMZBanner.start();
        // 设置页面改变监听器
        mMZBanner.addPageChangeLisnter(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                try {
                    if (tvPage != null) {
                        tvPage.setText(position + 1 + "/" + imageURLs.size());

                    }
                }catch (Exception e){
                    Log.e("TAG", "onPageSelected: "+e.getMessage() );
                }


            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        if (mYHousesEntity.getBody().isOffline()) {
            tvXiajia.setVisibility(View.VISIBLE);
            ll.setVisibility(View.GONE);
            tv_buy.setVisibility(View.GONE);
            tv_buy1.setVisibility(View.GONE);
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        mMZBanner.pause();//暂停轮播
    }

    @Override
    public void onResume() {
        super.onResume();
        mMZBanner.start();//开始轮播
    }


    private void initRGBottomView() {
        view0.setVisibility(View.INVISIBLE);
        view1.setVisibility(View.INVISIBLE);
        view2.setVisibility(View.INVISIBLE);
    }

    @Override //banner添加Page点击事件
    public void onPageClick(View view, int position) {
//ToastUtil.initToast(getContext(),position+"");
    }


    @TargetApi(Build.VERSION_CODES.KITKAT)
    @Override
    public void onCheckedChanged(RadioGroup radioGroup, @IdRes int i) {
        if (mYHousesEntity == null || mYHousesEntity.getBody() == null) {
            return;
        }
        initRGBottomView();
        switch (i) {
            case R.id.rb_0: {//房源详情
                view0.setVisibility(View.VISIBLE);
                if (mYHousesEntity.getBody().getDetail() != null) {
                    // tvH5.loadDataWithBaseURL("图书名", mYHousesEntity.getBody().getHouse().getDetail(), "text/html", "utf-8", null);
                    imageFillWidth(tvH5, mYHousesEntity.getBody().getDetail().replace("<p><br></p><p><br></p>", ""));

                    //tvH5.setText(Html.fromHtml(mYHousesEntity.getBody().getHouse().getDetail(), new URLImageGetter(tvH5, getContext()), null));

                }

            }
            break;
            case R.id.rb_1: {//周边玩乐
                view1.setVisibility(View.VISIBLE);
                if (mYHousesEntity.getBody().getVillage().getAround() != null) {
                    // tvH5.loadDataWithBaseURL("图书名", mYHousesEntity.getBody().getHouse().getVillage().getAround(), "text/html", "utf-8", null);
                    imageFillWidth(tvH5, mYHousesEntity.getBody().getVillage().getAround().replace("<p><br></p><p><br></p>", ""));

                    // tvH5.setText(Html.fromHtml(mYHousesEntity.getBody().getHouse().getVillage().getAround(), new URLImageGetter(tvH5, getContext()), null));
                }
            }
            break;
            case R.id.rb_2: {//小区环境
                view2.setVisibility(View.VISIBLE);
                if (mYHousesEntity.getBody().getVillage().getDetail() != null) {
                    //  tvH5.setText(Html.fromHtml(mYHousesEntity.getBody().getHouse().getVillage().getDetail(), new URLImageGetter(tvH5, getContext()), null));
                    imageFillWidth(tvH5, mYHousesEntity.getBody().getVillage().getDetail().replace("<p><br></p><p><br></p>", ""));

                    // tvH5.loadDataWithBaseURL("图书名", mYHousesEntity.getBody().getHouse().getVillage().getDetail(), "text/html", "utf-8", null);

                }
            }
            break;
        }
    }

    @TargetApi(Build.VERSION_CODES.KITKAT)
    @Override
    public void onResponse(String url, String json) {
        if (statusLayoutManager != null) {

            statusLayoutManager.showSuccessLayout();
        }
        dismissLoading();
        if (!TextUtils.isEmpty(json)) {
            if ((Constant.URL.houses + houseId).equals(url)) {
                LogeUtil.e("houses", json);
                mYHousesEntity = gson.fromJson(json, MYHousesEntity.class);
                if ("200".equals(mYHousesEntity.getCode())) {

                    initview(mYHousesEntity);

                } else {
                    ToastUtil.initToast(getContext(), mYHousesEntity.getMsg());
                }

            } else if (String.format(Constant.URL.similar_list, houseId).equals(url)) {
                LogeUtil.e("similar_list", json);
                SimilarListEntity similarListEntity = gson.fromJson(json, SimilarListEntity.class);
                if ("200".equals(similarListEntity.getCode())) {
                    if (similarListEntity.getBody().getDataList() != null) {
                        sameData.clear();
                        sameData.addAll(similarListEntity.getBody().getDataList());
                    }
                    similarListAdapter.setData(sameData);

                } else {
                    ToastUtil.initToast(getContext(), similarListEntity.getMsg());

                }

            } else if (String.format(Constant.URL.houses_states, houseId).equals(url)) {
                LogeUtil.e("houses_states", json);
                dismissLoading();
                housesStates = gson.fromJson(json, HousesStates.class);
                if ("200".equals(housesStates.getCode())) {
                    if (housesStates.getBody().getMonths() != null) {
                        dateCalendar.addAll(housesStates.getBody().getMonths());
                        if (sizeCalendar == -1) {

                            if (dateCalendar.size() > 0) {
                                currentCalendar = 0;
                                toolbarIconLeft.setSelected(false);
                                rvDate.scrollToPosition(0);
                                tvDate.setText(dateCalendar.get(currentCalendar).getList().get(0).getDate());
                                dateCalendarAdapter.setData(dateCalendar);
                            }


                        } else {
                            if (housesStates.getBody().getMonths() != null) {
                                dateCalendarAdapter.setData(dateCalendar);

                                currentCalendar = currentCalendar + 1;
                                tvDate.setText(dateCalendar.get(currentCalendar).getList().get(0).getDate());

                                rvDate.scrollToPosition(currentCalendar);
                                toolbarIconLeft.setSelected(true);
                            }


                        }
                        sizeCalendar = dateCalendar.size();
                    }


                } else {
                    ToastUtil.initToast(getContext(), housesStates.getMsg());

                }


            }
        }
    }


    @Override
    public void onFailure(String url, String error) {
        if (statusLayoutManager != null) {

            statusLayoutManager.showErrorLayout();
        }
        ToastUtil.initToast(getContext(), "网络错误");

        dismissLoading();
    }


    @OnClick({R.id.rl_zx, R.id.tv_favorite, R.id.tv_addr, R.id.tv_zx, R.id.tv_buy1, R.id.tv_buy, R.id.tv_tg, R.id.tv_change, R.id.toolbar_iconRight, R.id.toolbar_iconLeft, R.id.tv_sheshi})
    public void onViewClicked(View view) {
        if (mYHousesEntity == null || mYHousesEntity.getBody() == null) {
            return;
        }
        switch (view.getId()) {
            case R.id.tv_favorite: {//喜欢
                xihanChange();
            }
            break;
            case R.id.rl_zx:
            case R.id.tv_zx:
               /* Intent intent1 = new Intent(Intent.ACTION_DIAL);
                Uri data = Uri.parse("tel:" + "0755-26657792");
                intent1.setData(data);
                startActivity(intent1);*/
                ZXPopPT zXPop = new ZXPopPT(getContext(), getActivity(), mYHousesEntity);
                zXPop.showPopupWindow();


               /* KfStartHelper helper = new KfStartHelper(getActivity());
                LoginEntity userInfo = SharedPreferencesUtil.getUserInfo(getContext());

                CardInfo ci = null;
                try {
                    ci = new
                            CardInfo(mYHousesEntity.getBody().getImShareDTO().getImageURL(),
                            mYHousesEntity.getBody().getImShareDTO().getTitle(),
                            mYHousesEntity.getBody().getImShareDTO().getSurrounding(),
                            PhoneUtil.handleBalance((Long.parseLong(mYHousesEntity.getBody().getImShareDTO().getPrice()) / 100) + "", 2),
                            mYHousesEntity.getBody().getImShareDTO().getLinkURL());
                } catch (Exception e) {
                    e.printStackTrace();
                }

                //设置card
                helper.setCard(ci);
                //设置参数初始化
                helper.initSdkChat("com.villaday.idf.7mss",
                        userInfo.getBody().getMember().getNickName() + "",
                        userInfo.getBody().getMember().getId() + "");*/

                break;
            case R.id.tv_buy:
            case R.id.tv_buy1:
                if (mYHousesEntity != null) {
                    Intent intent3 = new Intent(getContext(), ChouseCheckInDateActivity.class);
                    intent3.putExtra("houseId", houseId);
                    intent3.putExtra("type", 0);
                    intent3.putExtra("product_id", mYHousesEntity.getBody().getId());
                    intent3.putExtra("product_type", 100);
                    intent3.putExtra("product_quantity", 1);
                    //intent3.putExtra("hasHouse", mYHousesEntity.getBody().is);


                    startActivity(intent3);
                }


                break;
            case R.id.tv_tg:
                ////2 小区，3 房源 ，7 酒店，52 特卖(预售)
                ShareUtils.getData(this,(AppCompatActivity) getActivity(), "3", houseId);
               // changePage.changePage();
                break;
            case R.id.tv_addr://地图

                Intent intent = new Intent();
                intent.setAction("android.intent.action.VIEW");
                Uri content_url = Uri.parse(String.format(Constant.URL.MapDiTu, mYHousesEntity.getBody().getLocation().getLatitude() + "", mYHousesEntity.getBody().getLocation().getLongitude() + "", mYHousesEntity.getBody().getAddress(), mYHousesEntity.getBody().getLocation().getCity()));
                LogeUtil.e("fa", mYHousesEntity.getBody().getLocation().getLatitude() + "ggg" + mYHousesEntity.getBody().getLocation().getLongitude() + "ggg" + mYHousesEntity.getBody().getAddress() + "gg" + mYHousesEntity.getBody().getLocation().getCity());

                intent.setData(content_url);
                startActivity(intent);
                break;
            case R.id.tv_change://换一批
                loadingDialog = LoadingDialog.newInstance("加载中");
                loadingDialog.show(getActivity().getFragmentManager(), "loading");
                pageNo++;
                getSameHouse();
                break;
            case R.id.toolbar_iconRight://日历移动
                if (dateCalendar != null && dateCalendar.size() != 0) {
                    chackRight();
                }

                break;
            case R.id.toolbar_iconLeft://日历移动
                if (dateCalendar != null && dateCalendar.size() != 0) {
                    chackLeft();
                }

                break;
            case R.id.tv_sheshi://配套设施
                if (mYHousesEntity.getBody() != null && mYHousesEntity.getBody().getFacilityMap() != null) {
                    List<SheBeiEntity> ssData = new ArrayList<>();
                    MYHousesEntity.BodyEntity.FacilityMapEntity facilityMap = mYHousesEntity.getBody().getFacilityMap();
                    if (facilityMap.getFEATURE() != null && facilityMap.getFEATURE().size() > 0) {
                        for (int i = 0; i < facilityMap.getFEATURE().size(); i++) {
                            ssData.add(new SheBeiEntity(facilityMap.getFEATURE().get(i).getCode(), facilityMap.getFEATURE().get(i).getIcon(), facilityMap.getFEATURE().get(i).getIconClass(), facilityMap.getFEATURE().get(i).getName()));

                        }
                        for (int i = 0; i < 4 - facilityMap.getFEATURE().size() % 4; i++) {
                            ssData.add(new SheBeiEntity(1));
                        }
                    }

                    if (facilityMap.getBASE() != null && facilityMap.getBASE().size() > 0) {
                        for (int i = 0; i < facilityMap.getBASE().size(); i++) {
                            ssData.add(new SheBeiEntity(facilityMap.getBASE().get(i).getCode(), facilityMap.getBASE().get(i).getIcon(), facilityMap.getBASE().get(i).getIconClass(), facilityMap.getBASE().get(i).getName()));

                        }
                        for (int i = 0; i < 4 - facilityMap.getBASE().size() % 4; i++) {
                            ssData.add(new SheBeiEntity(1));
                        }
                    }

                    if (facilityMap.getRECREATION() != null && facilityMap.getRECREATION().size() > 0) {
                        for (int i = 0; i < facilityMap.getRECREATION().size(); i++) {
                            ssData.add(new SheBeiEntity(facilityMap.getRECREATION().get(i).getCode(), facilityMap.getRECREATION().get(i).getIcon(), facilityMap.getRECREATION().get(i).getIconClass(), facilityMap.getRECREATION().get(i).getName()));

                        }
                        for (int i = 0; i < 4 - facilityMap.getRECREATION().size() % 4; i++) {
                            ssData.add(new SheBeiEntity(1));
                        }
                    }
                    if (facilityMap.getCLEAN_TOOL() != null && facilityMap.getCLEAN_TOOL().size() > 0) {
                        for (int i = 0; i < facilityMap.getCLEAN_TOOL().size(); i++) {
                            ssData.add(new SheBeiEntity(facilityMap.getCLEAN_TOOL().get(i).getCode(), facilityMap.getCLEAN_TOOL().get(i).getIcon(), facilityMap.getCLEAN_TOOL().get(i).getIconClass(), facilityMap.getCLEAN_TOOL().get(i).getName()));

                        }
                        for (int i = 0; i < 4 - facilityMap.getCLEAN_TOOL().size() % 4; i++) {
                            ssData.add(new SheBeiEntity(1));
                        }
                    }
                    if (facilityMap.getCLEAN_FACILITY() != null && facilityMap.getCLEAN_FACILITY().size() > 0) {
                        for (int i = 0; i < facilityMap.getCLEAN_FACILITY().size(); i++) {
                            ssData.add(new SheBeiEntity(facilityMap.getCLEAN_FACILITY().get(i).getCode(), facilityMap.getCLEAN_FACILITY().get(i).getIcon(), facilityMap.getCLEAN_FACILITY().get(i).getIconClass(), facilityMap.getCLEAN_FACILITY().get(i).getName()));

                        }
                        for (int i = 0; i < 4 - facilityMap.getCLEAN_FACILITY().size() % 4; i++) {
                            ssData.add(new SheBeiEntity(1));
                        }
                    }
                    if (facilityMap.getREPAST() != null && facilityMap.getREPAST().size() > 0) {
                        for (int i = 0; i < facilityMap.getREPAST().size(); i++) {
                            ssData.add(new SheBeiEntity(facilityMap.getREPAST().get(i).getCode(), facilityMap.getREPAST().get(i).getIcon(), facilityMap.getREPAST().get(i).getIconClass(), facilityMap.getREPAST().get(i).getName()));

                        }
                        for (int i = 0; i < 4 - facilityMap.getREPAST().size() % 4; i++) {
                            ssData.add(new SheBeiEntity(1));
                        }
                    }
                    if (facilityMap.getAROUND() != null && facilityMap.getAROUND().size() > 0) {
                        for (int i = 0; i < facilityMap.getAROUND().size(); i++) {
                            ssData.add(new SheBeiEntity(facilityMap.getAROUND().get(i).getCode(), facilityMap.getAROUND().get(i).getIcon(), facilityMap.getAROUND().get(i).getIconClass(), facilityMap.getAROUND().get(i).getName()));

                        }
                        for (int i = 0; i < 4 - facilityMap.getAROUND().size() % 4; i++) {
                            ssData.add(new SheBeiEntity(1));
                        }
                    }
                    if (facilityMap.getOTHER() != null && facilityMap.getOTHER().size() > 0) {
                        for (int i = 0; i < facilityMap.getOTHER().size(); i++) {
                            ssData.add(new SheBeiEntity(facilityMap.getOTHER().get(i).getCode(), facilityMap.getOTHER().get(i).getIcon(), facilityMap.getOTHER().get(i).getIconClass(), facilityMap.getOTHER().get(i).getName()));

                        }
                        for (int i = 0; i < 4 - facilityMap.getOTHER().size() % 4; i++) {
                            ssData.add(new SheBeiEntity(1));
                        }
                    }


                    Intent intent2 = new Intent(getContext(), FacilitiesActivity.class);
                    intent2.putParcelableArrayListExtra("data", (ArrayList<? extends Parcelable>) ssData);
                    startActivity(intent2);
                }

                break;
        }
    }

    public void xihanChange() {
        if (mYHousesEntity == null || mYHousesEntity.getBody() == null) {
            return;
        }
        loadingDialog = LoadingDialog.newInstance("操作中");
        loadingDialog.show(getActivity().getFragmentManager(), "loading");
                /*final behaviors behaviors = new behaviors(data.get((Integer) view.getTag()).isFavorite() ? 107 : 106
                        , new behaviors.ContextEntity(104, data.get((Integer) view.getTag()).getId()));
*/
        Favor collect = new Favor(!tvFavorite.isSelected());
        Map<String, Object> map = new HashMap<>();
        OkHttpUtil.postJson(getContext(), String.format(Constant.URL.member_favor, "3", mYHousesEntity.getBody().getId()), collect, map, new OkHttpUtil.OnDataListener() {
            @Override
            public void onResponse(String url, String json) {
                dismissLoading();

                LogeUtil.e("member_favor", json);
                behaviorsEntity behaviorsEntity = gson.fromJson(json, behaviorsEntity.class);

                if (behaviorsEntity.getBody().getStatus() == 1) {
                    tvFavorite.setSelected(!tvFavorite.isSelected());
                    if (onChangeFa != null) {
                        onChangeFa.onChangeFa(tvFavorite.isSelected());
                    }

                    ToastUtil.initToast(getContext(), tvFavorite.isSelected() ? "已喜欢" : "已取消喜欢");

                } else if (behaviorsEntity.getBody().getStatus() == 0) {

                    ToastUtil.initToast(getContext(), "操作失败");

                } else {
                    ToastUtil.initToast(getContext(), "操作失败");

                }

            }

            @Override
            public void onFailure(String url, String error) {

            }
        });
    }

    private void chackRight() {
        if (currentCalendar != -1) {
            if (currentCalendar == dateCalendar.size() - 1) {
                loadingDialog = LoadingDialog.newInstance("加载中");
                loadingDialog.show(getActivity().getFragmentManager(), "loading");
                currentTime = housesStates.getBody().getNextMonth();
                getCalendar();
            } else {
                if (dateCalendar.size() - 1 > currentCalendar)
                    currentCalendar = currentCalendar + 1;
                tvDate.setText(dateCalendar.get(currentCalendar).getList().get(0).getDate());

                rvDate.scrollToPosition(currentCalendar);
                toolbarIconLeft.setSelected(true);
            }
        } else {


        }


    }


    private void chackLeft() {

        if (currentCalendar != 0) {
            currentCalendar = currentCalendar - 1;
            tvDate.setText(dateCalendar.get(currentCalendar).getList().get(0).getDate());

            rvDate.scrollToPosition(currentCalendar);
            if (currentCalendar == 0) {
                toolbarIconLeft.setSelected(false);
            } else {
                toolbarIconLeft.setSelected(true);

            }
        }
    }

    @Override//配套设施点击
    public void onItemClick(View v, int position) {

    }

    @OnClick({R.id.tv_openAndClose, R.id.ll_openAndClose})
    public void onViewClicked() {

        if (tvOpenAndClose.isSelected()) {
            setWebViewHight(false);
            tvOpenAndClose.setText("展开全文");
            viewAlph.setVisibility(View.VISIBLE);
        } else {
            setWebViewHight(true);
            tvOpenAndClose.setText("收起全文");
            viewAlph.setVisibility(View.GONE);


        }
        tvOpenAndClose.setSelected(!tvOpenAndClose.isSelected());
    }


    public static class BannerViewHolder implements MZViewHolder<String> {
        private SimpleDraweeView mImageView;

        @Override
        public View createView(Context context) {
            // 返回页面布局
            View view = LayoutInflater.from(context).inflate(R.layout.banner_item, null);
            mImageView = (SimpleDraweeView) view.findViewById(R.id.banner_image);
            return view;
        }

        @Override
        public void onBind(Context context, int position, String data) {
            // 数据绑定
            // mImageView.setImageURI(new Uri.Builder().scheme("res").path(String.valueOf(data)).build());
            mImageView.setImageURI(data);
        }
    }

    public class URLImageGetter implements Html.ImageGetter {
        Context c;
        TextView tv_image;
        private List<Target> targets = new ArrayList<>();

        public URLImageGetter(TextView t, Context c) {
            this.tv_image = t;
            this.c = c;
            tv_image.setTag(targets);
        }

        @Override
        public Drawable getDrawable(final String source) {
            final URLDrawable urlDrawable = new URLDrawable();
            final Target target = new Target() {
                @Override
                public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
                    Drawable drawable = new BitmapDrawable(bitmap);
                    drawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
                    urlDrawable.setDrawable(drawable);
                    urlDrawable.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight());
                    tv_image.invalidate();
                    tv_image.setText(tv_image.getText());
                }

                @Override
                public void onBitmapFailed(Exception e, Drawable errorDrawable) {
                    errorDrawable.setBounds(0, 0, errorDrawable.getIntrinsicWidth(), errorDrawable.getIntrinsicHeight());
                    urlDrawable.setBounds(0, 0, errorDrawable.getIntrinsicWidth(), errorDrawable.getIntrinsicHeight());
                    urlDrawable.setDrawable(errorDrawable);
                    tv_image.invalidate();
                }


                @Override
                public void onPrepareLoad(Drawable placeHolderDrawable) {
                    placeHolderDrawable.setBounds(0, 0, placeHolderDrawable.getIntrinsicWidth(), placeHolderDrawable.getIntrinsicHeight());
                    urlDrawable.setBounds(0, 0, placeHolderDrawable.getIntrinsicWidth(), placeHolderDrawable.getIntrinsicHeight());
                    urlDrawable.setDrawable(placeHolderDrawable);
                    tv_image.invalidate();
                }
            };

            targets.add(target);
            loadPlaceholder(c, source, target);
            return urlDrawable;
        }

        public void loadPlaceholder(Context context, String url, Target target) {

            Picasso picasso = new Picasso.Builder(context).loggingEnabled(true).build();
            picasso.load(url)
                    .placeholder(R.drawable.img_order)
                    .error(R.drawable.img_order)
                    .into(target);
        }


    }


    public class URLDrawable extends BitmapDrawable {
        private Drawable drawable;

        @Override
        public void draw(Canvas canvas) {
            if (drawable != null) {
                drawable.draw(canvas);
            }
        }

        public void setDrawable(Drawable drawable) {
            this.drawable = drawable;
        }

    }

    private void dismissLoading() {
        if (loadingDialog != null) {
            loadingDialog.dismiss();
        }

    }

    public interface ChangePage {
        void changePage();
    }

    public boolean getLikeStata() {
        if (onChangeFa != null) {
            onChangeFa.onChangeFa(tvFavorite.isSelected());
        }

        return tvFavorite.isSelected();
    }

    public void shareXCX() {

        if (mYHousesEntity != null) {

            new Thread(new Runnable() {
                @Override
                public void run() {
                    MYHousesEntity.BodyEntity.ShareResponseEntity shareResponse = mYHousesEntity.getBody().getShareResponse();


                    File file = saveImageToSdCard(getContext(), shareResponse.getImageUrl());

                    String fileName = file.getAbsolutePath();


                    WXMiniProgramObject miniProgramObj = new WXMiniProgramObject();
                    miniProgramObj.webpageUrl = shareResponse.getLink(); // 兼容低版本的网页链接
/*
        miniProgramObj.miniprogramType = WXMiniProgramObject.MINIPTOGRAM_TYPE_RELEASE;// 正式版:0，测试版:1，体验版:2
*/
                    miniProgramObj.userName = shareResponse.getMiniAppId();     // 小程序原始id
                    miniProgramObj.path = shareResponse.getPath();            //小程序页面路径
                    WXMediaMessage msg = new WXMediaMessage(miniProgramObj);
                    msg.title = shareResponse.getTitle();                 // 小程序消息title
                    msg.description = shareResponse.getDesc();
                    Bitmap bitmap = BitMapUtil.getBitmap(fileName);

                    msg.thumbData = BitMapUtil.compressBitmap(bitmap, 80 * 1024);// 小程序消息desc

                    SendMessageToWX.Req req = new SendMessageToWX.Req();
                    req.transaction = "webpage";
                    req.message = msg;
                    req.scene = SendMessageToWX.Req.WXSceneSession;  // 目前支持会话
                    IWXAPI api = WXAPIFactory.createWXAPI(getContext(), Constant.ID.WeChat_APP_ID, false);

                    api.sendReq(req);
                }
            }).start();

        }


    }

    //根据网络图片url路径保存到本地
    public File saveImageToSdCard(Context context, String image) {
        boolean success = false;
        File file = null;
        try {

            file = createStableImageFile(context);
            Bitmap bitmap = null;
            URL url = new URL(image);
            HttpURLConnection conn = null;
            conn = (HttpURLConnection) url.openConnection();
            InputStream is = null;
            is = conn.getInputStream();
            bitmap = BitmapFactory.decodeStream(is);

            FileOutputStream outStream;

            outStream = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, outStream);
            outStream.flush();
            outStream.close();
            success = true;
            //MediaStore.Images.Media.insertImage(context.getContentResolver(), image, file.getName(), "你对图片的描述");

        } catch (Exception e) {
            e.printStackTrace();
        }

        if (success) {

            return file;
        } else {
            return null;
        }
    }

    //创建本地保存路径
    public static File createStableImageFile(Context context) throws IOException {

        String imageFileName = "shareXCX" + System.currentTimeMillis() + ".jpg";
        File storageDir = context.getExternalCacheDir();
        File image = new File(storageDir, imageFileName);
        return image;
    }

    public void setChangeTabPosition(GoodsFragmentFor3.ChangeTabPosition changeTabPosition) {


        this.changeTabPosition = changeTabPosition;
    }
    @Override
    public boolean onBackPressed() {
        if (vImageWatcher == null) {
            return false;
        } else {
            // 当确认没有子Fragmnt时可以直接return false
            if (!vImageWatcher.handleBackPressed()) {
                return BackHandlerHelper.handleBackPress(this);
            } else {
                return !BackHandlerHelper.handleBackPress(this);
            }
        }
    }
}
